<template>
    <div>
        <div class="bottonBox" style="padding: 10px;background-color: #f3f3f3;">
            <button type="button" class="btn btn-primary" @click="goback"><li class="fa fa-reply"></li>返回</button>
            <button type="button" class="btn btn-success" v-if="postData.method!='watch'" @click="save"><li class="glyphicon glyphicon-floppy-disk"></li>保存</button>
            <button type="button" class="btn btn-default" v-if="postData.method!='add'" @click="proData"><li class="fa fa-long-arrow-up"></li>上一条</button>
            <button type="button" class="btn btn-default" v-if="postData.method!='add'" @click="nextData"><li class="fa fa-long-arrow-down"></li>下一条</button>
        </div>
        <div class="textBox" style="margin: 20px auto;padding: 10px;background-color: #f3f3f3;">
            <div style="font-size: 20px;width: 140px;background-color: white;padding: 8px;border-radius: 5px;">
                <li class="glyphicon glyphicon-file"></li>缩略词信息
            </div>
            <div class="word-row">
                <div class="word-col">*缩略词：</div>
                    <input v-if="postData.method=='watch'" class="word-input" type="text"  disabled ="disabled"  v-model="postData.abb"/>
                    <input v-else class="word-input" type="text"  v-model="postData.abb"/>
            </div>
            <div  class="word-row">
                <div class="word-col">*含义：</div>
                <input v-if="postData.method=='watch'" class="word-input" type="text" disabled ="disabled" v-model="postData.mean"/>
                <input v-else class="word-input" type="text" v-model="postData.mean"/>
            </div>
            <div  class="word-row">
                <div class="word-col">详细信息：</div>
                <textarea v-if="postData.method=='watch'" class="word-input" style="height: 80px" disabled ="disabled" v-model="postData.detail"></textarea>
                <textarea v-else class="word-input" style="height: 80px" v-model="postData.detail"></textarea>
            </div>
        </div>
        <div class="bottonBox" style="padding: 10px;background-color: #f3f3f3;">
            <button type="button" class="btn btn-primary" @click="goback"><li class="fa fa-reply"></li>返回</button>
            <button type="button" class="btn btn-success" v-if="postData.method!='watch'" @click="save"><li class="glyphicon glyphicon-floppy-disk"></li>保存</button>
            <button type="button" class="btn btn-default" v-if="postData.method!='add'" @click="proData"><li class="fa fa-long-arrow-up"></li>上一条</button>
            <button type="button" class="btn btn-default" v-if="postData.method!='add'" @click="nextData"><li class="fa fa-long-arrow-down"></li>下一条</button>
        </div>
    </div>
</template>
<script>
    export default {
        name: "package-msg-edit",
        data() {
            return {
                postData:{
                    method:"",
                    abb:"",
                    mean:"",
                    detail:"",
                    watchCdt:"",
                    watchId:"",
                    rowno:""
                }
            }
        },
        methods:{
            goback:function(){
                this.$router.push({path:'/WebPlatform/Package'})
                // this.$router.push({name:'abbList'})
            },
            save:function(){
                if(this.postData.method=="add"){
                    getDataSync("http://localhost:8084/demo/hello","post",{"filter":JSON.stringify(this.postData)},function(data){
                        console.log(data)
                    })
                    this.$router.push({path:'/WebPlatform/Package'})
                }else if(this.postData.method=="edit"){
                    this.postData.method="update"
                    getDataSync("http://localhost:8084/demo/hello","post",{"filter":JSON.stringify(this.postData)},data=>{
                        console.log(data)
                        this.$message({
                            message: '修改成功',
                            type: 'success'
                        });
                    })
                    this.postData.method="edit"
                }

            },
            watchData:function(){
                // this.postData.watchCdt=this.$route.query.watchCdt;
                this.postData.watchId=this.$route.query.watchId;
                // this.postData.rowno=this.$route.query.rowno;
                getDataSync("http://localhost:8084/demo/hello","post",{"filter":JSON.stringify(this.postData)},data=>{
                    this.postData.abb=data.abb;
                    this.postData.mean=data.mean;
                    this.postData.detail=data.detail;
                    console.log(this.postData)
                })
            },
            nextData:function(){
                getDataSync("http://localhost:8084/demo/nextData","post",{"filter":JSON.stringify(this.postData)},data=>{
                    if(data.result=="success"){
                        this.postData.abb=data.abb;
                        this.postData.mean=data.mean;
                        this.postData.detail=data.detail;
                        this.postData.watchId = data.id;
                        this.$router.push({path:'/WebPlatform/PackageMsgEdit',
                            query: {
                                method:this.postData.method,
                                // watchCdt:$("#editabledatatable").data('bs.datagrid17').getSelectedRowData().abb,
                                watchId:this.postData.watchId,
                                // rowno:$("#editabledatatable").data('bs.datagrid17').getSelectedRowData().rowno
                            }
                        })
                    }else{
                        this.$message({
                            message: '已是最后一条',
                            type: 'warning'
                        });
                        return false;
                    }
                })
            },
            proData:function(){
                getDataSync("http://localhost:8084/demo/proData","post",{"filter":JSON.stringify(this.postData)},data=>{
                    if(data.result=="success"){
                        this.postData.abb=data.abb;
                        this.postData.mean=data.mean;
                        this.postData.detail=data.detail;
                        this.postData.watchId = data.id;
                        this.$router.push({path:'/WebPlatform/PackageMsgEdit',
                            query: {
                                method:this.postData.method,
                                // watchCdt:$("#editabledatatable").data('bs.datagrid17').getSelectedRowData().abb,
                                watchId:this.postData.watchId,
                                // rowno:$("#editabledatatable").data('bs.datagrid17').getSelectedRowData().rowno
                            }
                        })
                    }else{
                        this.$message({
                            message: '已是第一条',
                            type: 'warning'
                        });
                        return false;
                    }
                })
            }
        },
        created(){
            this.postData.method=this.$route.query.method;
            if(this.postData.method=="watch"||this.postData.method=="edit"){
                this.watchData();
            }
        }
    }
</script>

<style>
    #page-body{
        background-color: white
    }
    .word-row{
        margin-bottom: 30px;
    }
    .word-col{
        float: left;
        width: 35%;
        text-align: right;
        font-size: 20px;
        margin-right: 5%;
    }
    .word-input{
        width: 60%;
        height: 30px;
        padding-left: 10px;
    }
</style>